#include "Pixel.h"

Pixel::Pixel()
{
	red = green = blue = 0;
}

Pixel::Pixel(const int r, const int g, const int b)
{
	red = r;
	green = g;
	blue = b;
}

Pixel::Pixel(const Pixel &value)
{
	red = value.red;
	green = value.green;
	blue = value.blue;
}

Pixel::~Pixel()
{
	
}

// Assignment operator
const Pixel& Pixel::operator = (const Pixel &value)
{
	red = value.red;
	green = value.green;
	blue = value.blue;

	return *this;
}

// Logical operator: euqal to
bool Pixel::operator == (const Pixel &value)
{
	if (red != value.red || green != value.green || blue != value.blue)
		return false;

	return true;
}

// Logical operator: not euqal to
bool Pixel::operator != (const Pixel &value)
{
	return (*this == value) ? false : true;
}

Pixel Pixel::operator + (const Pixel &value)
{
	Pixel result;

	result.red = red + value.red;
	result.green = green + value.green;
	result.blue = blue + value.blue;

	if (result.red > 255)
		result.red = 255;

	if (result.green > 255)
		result.green = 255;

	if (result.blue > 255)
		result.blue = 255;

	return result;
}

Pixel Pixel::operator - (const Pixel &value)
{
	Pixel result;

	result.red = red - value.red;
	result.green = green - value.green;
	result.blue = blue - value.blue;

	if (result.red < 0)
		result.red = 0;

	if (result.green < 0)
		result.green = 0;

	if (result.blue < 0)
		result.blue = 0;

	return result;
}

Pixel Pixel::operator * (const Pixel &value)
{
	Pixel result;

	result.red = red * value.red;
	result.green = green * value.green;
	result.blue = blue * value.blue;

	if (result.red > 255)
		result.red = 255;

	if (result.green > 255)
		result.green = 255;

	if (result.blue > 255)
		result.blue = 255;

	return result;
}

Pixel Pixel::operator * (const int &num)
{
	Pixel result;

	result.red = red * num;
	result.green = green * num;
	result.blue = blue * num;

	if (result.red > 255)
		result.red = 255;

	if (result.green > 255)
		result.green = 255;

	if (result.blue > 255)
		result.blue = 255;

	return result;
}

Pixel Pixel::operator / (const int &num)
{
	Pixel result;

	result.red = red / num;
	result.green = green / num;
	result.blue = blue / num;

	if (result.red < 0)
		result.red = 0;

	if (result.green < 0)
		result.green = 0;

	if (result.blue < 0)
		result.blue = 0;

	return result;
}

istream &operator >> (istream& input, Pixel &value)
{
	input >> value.red >> value.green >> value.blue;

	return input;
}

ostream &operator << (ostream& output, const Pixel &value)
{
	output << value.red << " " << value.green << " " << value.blue;

	return output;
}
